/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dyniablaster.graphics;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import java.io.IOException;
import java.util.Vector;

/**
 * @author Damian2
 */
public class DyniaBlasterDesign {

    //<editor-fold defaultstate="collapsed" desc=" Generated Fields ">//GEN-BEGIN:|fields|0|
    private Image topview_tiles;
    private TiledLayer floor;
    private Image platform_tiles;
    private TiledLayer labirynt;
    private Image fire_central;
    private Image bomb;
    private Sprite bomby;
    public int bombyseq001Delay = 200;
    public int[] bombyseq001 = {0, 0, 0, 0};
    public int boomDelay = 200;
    public int[] boom = {1, 1, 1, 1};
    private Image postacie2;
    private Sprite player;
    public int leftDelay = 180;
    public int[] left = {1, 16, 1, 31};
    public int downDelay = 180;
    public int[] down = {0, 15, 0, 30};
    public int rightDelay = 180;
    public int[] right = {3, 18, 3, 33};
    public int dieDelay = 180;
    public int[] die = {19, 20, 21, 34, 35, 36};
    public int up1Delay = 180;
    public int[] up1 = {2, 17, 2, 32};
    private Sprite player1;
    public int goLeftDelay = 200;
    public int[] goLeft = {100, 101, 102, 103};
    public int goUpDelay = 200;
    public int[] goUp = {96, 95, 96, 97};
    public int goDownDelay = 200;
    public int[] goDown = {88, 89, 90, 91};
    private Image dyniaBomb;
    //</editor-fold>//GEN-END:|fields|0|
    private Vector bombs;
    static int bombsCount = 5;
    //<editor-fold defaultstate="collapsed" desc=" Generated Methods ">//GEN-BEGIN:|methods|0|
    //</editor-fold>//GEN-END:|methods|0|

    public void updateLayerManagerForScena(LayerManager lm) throws java.io.IOException//GEN-BEGIN:|1-updateLayerManager|0|1-preUpdate
    {//GEN-END:|1-updateLayerManager|0|1-preUpdate
        // write pre-update user code here
        bombs = new Vector();
        getPlayer().setPosition(111, 175);
        getPlayer().setVisible(false);
        lm.append(getPlayer());
        getPlayer1().setPosition(111, 175);
        getPlayer1().setVisible(true);
        lm.append(getPlayer1());
        setDynia2();
        for(int i=0; i<bombsCount; i++)
            lm.append((Sprite)bombs.elementAt(i));

        getLabirynt().setPosition(-64, 0);//GEN-BEGIN:|1-updateLayerManager|1|1-postUpdate
        getLabirynt().setVisible(true);
        lm.append(getLabirynt());
        getFloor().setPosition(0, 0);
        getFloor().setVisible(true);
        lm.append(getFloor());//GEN-END:|1-updateLayerManager|1|1-postUpdate
        // write post-update user code here


    }//GEN-BEGIN:|1-updateLayerManager|2|
//GEN-END:|1-updateLayerManager|2|

    public Image getTopview_tiles() throws java.io.IOException//GEN-BEGIN:|2-getter|0|2-preInit
    {
        if (topview_tiles == null)
        {//GEN-END:|2-getter|0|2-preInit
            // write pre-init user code here
            topview_tiles = Image.createImage("/topview_tiles.png");//GEN-BEGIN:|2-getter|1|2-postInit
        }//GEN-END:|2-getter|1|2-postInit
        // write post-init user code here
        return this.topview_tiles;//GEN-BEGIN:|2-getter|2|
    }
//GEN-END:|2-getter|2|

    public TiledLayer getFloor() throws java.io.IOException//GEN-BEGIN:|3-getter|0|3-preInit
    {
        if (floor == null)
        {//GEN-END:|3-getter|0|3-preInit
            // write pre-init user code here
            floor = new TiledLayer(20, 22, getTopview_tiles(), 16, 16);//GEN-BEGIN:|3-getter|1|3-midInit
            int[][] tiles = {
                { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
            };//GEN-END:|3-getter|1|3-midInit
            // write mid-init user code here
            for (int row = 0; row < 22; row++)//GEN-BEGIN:|3-getter|2|3-postInit
            {
                for (int col = 0; col < 20; col++)
                {
                    floor.setCell(col, row, tiles[row][col]);
                }
            }
        }//GEN-END:|3-getter|2|3-postInit
        // write post-init user code here
        return floor;//GEN-BEGIN:|3-getter|3|
    }
//GEN-END:|3-getter|3|

    public Image getPlatform_tiles() throws java.io.IOException//GEN-BEGIN:|4-getter|0|4-preInit
    {
        if (platform_tiles == null)
        {//GEN-END:|4-getter|0|4-preInit
            // write pre-init user code here
            platform_tiles = Image.createImage("/platform_tiles.png");//GEN-BEGIN:|4-getter|1|4-postInit
        }//GEN-END:|4-getter|1|4-postInit
        // write post-init user code here
        return this.platform_tiles;//GEN-BEGIN:|4-getter|2|
    }
//GEN-END:|4-getter|2|

    public TiledLayer getLabirynt() throws java.io.IOException//GEN-BEGIN:|5-getter|0|5-preInit
    {
        if (labirynt == null)
        {//GEN-END:|5-getter|0|5-preInit
            // write pre-init user code here
            labirynt = new TiledLayer(24, 21, getPlatform_tiles(), 16, 16);//GEN-BEGIN:|5-getter|1|5-midInit
            int[][] tiles = {
                { 0, 0, 0, 0, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 0 },
                { 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0 },
                { 0, 0, 0, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0 },
                { 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0 },
                { 0, 0, 0, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0 },
                { 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0 },
                { 0, 0, 0, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0 },
                { 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0 },
                { 0, 0, 0, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0 },
                { 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0 },
                { 0, 0, 0, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0 },
                { 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0 },
                { 0, 0, 0, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0 },
                { 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0 },
                { 0, 0, 0, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0 },
                { 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0 },
                { 0, 0, 0, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0 },
                { 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0 },
                { 0, 0, 0, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0 },
                { 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0 },
                { 0, 0, 0, 0, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 0 }
            };//GEN-END:|5-getter|1|5-midInit
            // write mid-init user code here
            for (int row = 0; row < 21; row++)//GEN-BEGIN:|5-getter|2|5-postInit
            {
                for (int col = 0; col < 24; col++)
                {
                    labirynt.setCell(col, row, tiles[row][col]);
                }
            }
        }//GEN-END:|5-getter|2|5-postInit
        // write post-init user code here
        return labirynt;//GEN-BEGIN:|5-getter|3|
    }
//GEN-END:|5-getter|3|

    public Image getPostacie2() throws java.io.IOException//GEN-BEGIN:|33-getter|0|33-preInit
    {
        if (postacie2 == null)
        {//GEN-END:|33-getter|0|33-preInit
            // write pre-init user code here
            postacie2 = Image.createImage("/postacie2.png");//GEN-BEGIN:|33-getter|1|33-postInit
        }//GEN-END:|33-getter|1|33-postInit
        // write post-init user code here
        return this.postacie2;//GEN-BEGIN:|33-getter|2|
    }
//GEN-END:|33-getter|2|



    public Sprite getPlayer() throws java.io.IOException//GEN-BEGIN:|36-getter|0|36-preInit
    {
        if (player == null)
        {//GEN-END:|36-getter|0|36-preInit
            // write pre-init user code here
            player = new Sprite(getPostacie2(), 16, 23);//GEN-BEGIN:|36-getter|1|36-postInit
            player.setFrameSequence(right);//GEN-END:|36-getter|1|36-postInit
            // write post-init user code here
        }//GEN-BEGIN:|36-getter|2|
        return player;
    }
//GEN-END:|36-getter|2|

    public Sprite getPlayer1() throws java.io.IOException//GEN-BEGIN:|55-getter|0|55-preInit
    {
        if (player1 == null)
        {//GEN-END:|55-getter|0|55-preInit
            // write pre-init user code here
            player1 = new Sprite(getTopview_tiles(), 16, 16);//GEN-BEGIN:|55-getter|1|55-postInit
            player1.setFrameSequence(goDown);//GEN-END:|55-getter|1|55-postInit
            // write post-init user code here
        }//GEN-BEGIN:|55-getter|2|
        return player1;
    }
//GEN-END:|55-getter|2|

    public Image getDyniaBomb() throws java.io.IOException//GEN-BEGIN:|59-getter|0|59-preInit
    {
        if (dyniaBomb == null)
        {//GEN-END:|59-getter|0|59-preInit
            // write pre-init user code here
            dyniaBomb = Image.createImage("/dyniaBomb.png");//GEN-BEGIN:|59-getter|1|59-postInit
        }//GEN-END:|59-getter|1|59-postInit
        // write post-init user code here
        return this.dyniaBomb;//GEN-BEGIN:|59-getter|2|
    }
//GEN-END:|59-getter|2|



    public Image getFire_central() throws java.io.IOException//GEN-BEGIN:|142-getter|0|142-preInit
    {
        if (fire_central == null)
        {//GEN-END:|142-getter|0|142-preInit
            // write pre-init user code here
            fire_central = Image.createImage("/fire_central.png");//GEN-BEGIN:|142-getter|1|142-postInit
        }//GEN-END:|142-getter|1|142-postInit
        // write post-init user code here
        return this.fire_central;//GEN-BEGIN:|142-getter|2|
    }
//GEN-END:|142-getter|2|



    public Image getBomb() throws java.io.IOException//GEN-BEGIN:|145-getter|0|145-preInit
    {
        if (bomb == null)
        {//GEN-END:|145-getter|0|145-preInit
            // write pre-init user code here
            bomb = Image.createImage("/bomb.png");//GEN-BEGIN:|145-getter|1|145-postInit
        }//GEN-END:|145-getter|1|145-postInit
        // write post-init user code here
        return this.bomb;//GEN-BEGIN:|145-getter|2|
    }
//GEN-END:|145-getter|2|

    public Sprite getBomby() throws java.io.IOException//GEN-BEGIN:|146-getter|0|146-preInit
    {
        if (bomby == null)
        {//GEN-END:|146-getter|0|146-preInit
            // write pre-init user code here
            bomby = new Sprite(getBomb(), 16, 16);//GEN-BEGIN:|146-getter|1|146-postInit
            bomby.setFrameSequence(bombyseq001);//GEN-END:|146-getter|1|146-postInit
            // write post-init user code here
        }//GEN-BEGIN:|146-getter|2|
        return bomby;
    }
//GEN-END:|146-getter|2|
     public void setDynia2() throws java.io.IOException
    {
         Sprite temp;
         for(int i=0; i<bombsCount; i++)
         {
             temp = new Sprite(getBomb(), 16, 16);
             temp.setFrameSequence(bombyseq001);
             temp.setVisible(false);
             bombs.addElement(temp);
         }

    }
     public Sprite getDynia2(int i)
     {
        return (Sprite)bombs.elementAt(i);
     }


    public int setBomb(int x, int y) throws IOException
    {
        for(int i = 0; i<bombsCount; i++)
        {
            if(!getDynia2(i).isVisible())
            {
                getDynia2(i).setPosition(x, y);
                getDynia2(i).setFrameSequence(bombyseq001);
                getDynia2(i).setVisible(true);
                //i = bombsCount + 3;  //wyjscie z petli for jezeli znaleziono wolne miejsce na bombe
                return i;
            }
        }
        return -1;
  
    }

    public void boom(int i)
    {
        getDynia2(i).setFrameSequence(boom);
    }

    public void destroyBomb(int i)
    {
        getDynia2(i).setVisible(false);
    }
}
